package lagouHomeWork;


/**
 * @author StarryHorizon
 * @create 2022-01-04 14:52
 */
public class Worker {

    private String name;
    private int age;

    public Worker(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Worker() {
    }

    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name == null || name == "") {
            throw new NullPointerException();
        }
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age >= 18 && age <= 150) {
            this.age = age;
        } else {
            try {
                throw new AgeException("年龄异常");
            } catch (AgeException e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) {

        //创建worker对象并测试
        Worker worker = new Worker();
//        worker.setAge(18);
//        System.out.println("年龄：" + worker);

        worker.setName("fds");
        System.out.println("姓名：" + worker);
    }
}
